const schedule = require('node-schedule')

schedule.scheduleJob('*/15 * * * *', async () => {
  const q = new Parse.Query('RoTask')
  q.equalTo('done', 1)
  q.notEqualTo('exported',true)
  q.notEqualTo('canSale',true)
  q.ascending('endTime')
  q.limit(1000)

  const list = await q.find()
  
  const now = new Date()
  list.forEach(item=>{
    const ft = item.get('endTime')
    const ct = item.get('checkTime')
    if(ft){
      const d = (now.getTime() - ft.getTime()) /(24*3600*1000)
      const days=Math.floor(d)
      if(days>=1){
        item.set('canSale',true)
        if(ct){
          const d2 = (ct.getTime()-ft.getTime()) /(24*3600*1000)
          const days2=Math.floor(d2)
          if(days2<1 && item.get('alive')!='死'){
            item.set('needCheck',true)
          }
        }
      }else{
        item.set('canSale',false)
      }
    }
  })
  console.log('>>>>>>>>>>>>>>>>>>findCanSaleMomoId>>>>>>>>>>>>>>>>>>>>[2]')
  await Parse.Object.saveAll(list)
  console.log('>>>>>>>>>>>>>>>>>>findCanSaleMomoId>>>>>>>>>>>>>>>>>>>>[3]')
})
